home *** CD-ROM | disk | FTP | other *** search
- /* Amigatized mini clone of chmod, capable of setting Amiga specific
- * file/drawer attributes.
- */
-
- #include <dos/dos.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <stdio.h> /* Needed by ix(_amiga).h. */
- /* Hack to find out if include files are for ixemul version 47+ or not. */
- #define __pos__
- #ifndef CTOBPTR
- #define ix_select extselect
- #include <ix_amiga.h>
- #else
- #define __INCLV47__
- #include <ix.h>
- #endif
- #undef __pos__
-
- #ifndef __INCLV47__
- #define ix_chmod(a,b) achmod(a,b)
- #endif
-
- void usage (void);
-
- int main (int argc, char *argv[])
- {
- unsigned long attrs, protbits;
- char *end;
- unsigned long i;
-
- /* Needs an attribute mask and at least one file/drawer name. */
- if (argc <= 2)
- {
- usage ();
- return (5);
- }
-
- /* Attribute string must not be empty. */
- if (argv[1][0] == '\0')
- {
- usage ();
- return (5);
- }
-
- errno = 0;
- attrs = strtol (argv[1], &end, 16);
-
- /* Attribute string must be fully convertible and not overflow. */
- if (*end != '\0' || errno != 0)
- {
- usage ();
- return (5);
- }
-
- /* Convert the attributes to protection bits required by ix_chmod(). */
- /* User delete/execute/write/read bits. */
- protbits = (attrs & 0x00F00) >> 2*4;
-
- /* User delete/execute/write/read bits are "active low". */
- protbits ^= FIBF_DELETE | FIBF_EXECUTE | FIBF_WRITE | FIBF_READ;
-
- /* Group delete/execute/write/read bits. */
- protbits |= (attrs & 0x000F0) << 1*4;
-
- /* Other delete/execute/write/read bits. */
- protbits |= (attrs & 0x0000F) << 3*4;
-
- /* Lower attribute bits (archive/pure/script). */
- protbits |= (attrs & 0x0F000) >> 2*4;
-
- /* Upper attribute bits (setgid/setuid). */
- protbits |= (attrs & 0xF0000) << 12;
-
- for (i = 2; i < argc; i ++)
- {
- ix_chmod (argv[i], protbits);
- }
-
- return (0);
- }
-
- void usage (void)
- {
- puts ("Usage: minichmod attributes file ...\n"
- "\n"
- "Attributes are specified as a five digit hexadecimal number\n"
- "(the letters A-F are the digits 10-15).\n"
- "The five digits 'mpugo' work like this:\n"
- "m: MultiUser attributes.\n"
- " 8 = Change owner during execution.\n"
- " 4 = Change group during execution.\n"
- "\n"
- "p: Standard file attributes.\n"
- " 4 = File is a script file.\n"
- " 2 = File is a residentable programme.\n"
- " 1 = File has been archived (cleared on changes).\n"
- "\n"
- "ugo: User, group, other permissions.\n"
- " 8 = File is readable.\n"
- " 4 = File is writable.\n"
- " 2 = File is executable.\n"
- " 1 = File is deletable.\n"
- "\n"
- "Attributes are combined by adding them.");
- }
-